//双方人数1-10
window._CTZ = [
  {
      "lv": 25,
      "name": "烈火挑战",
      "reward": "烈火符文",
      "player": [
          "飞箭羽",
      ],
      "army": [
          "武剑心",
          "武剑心",
          "武剑心"
      ]
  },
  {
      "lv": 50,
      "name": "枪棒挑战",
      "reward": "枪棒符文",
      "player": [
          "青阳仙",
          "青阳仙",
          "青阳仙"
      ],
      "army": [
          "魅影客",
          "魅影客",
          "魅影客",
      ]
  },
  {
      "lv": 75,
      "name": "盗术挑战",
      "reward": "盗术符文",
      "player": [
          "石断岳",
          "青阳仙",
          "风行者",
          "风行者",
          "风行者"
      ],
      "army": [
          "武剑心",
          "武剑心",
          "武剑心",
          "武剑心",
          "武剑心",
          "武剑心",
          "武剑心",
          "武剑心",
          "武剑心",
          "武剑心"
      ]
  },
  {
      "lv": 100,
      "name": "身法挑战",
      "reward": "身法符文",
      "player": [
        "龙太子",
        "龙太子",
        "龙太子"
      ],
      "army": [
        "道玄尘",
        "道玄尘",
        "道玄尘",
        "道玄尘",
        "道玄尘",
        "道玄尘",
        "道玄尘",
        "道玄尘"
      ]
  },
  {
      "lv": 125,
      "name": "御宝挑战",
      "reward": "御宝符文",
      "player": [
          "武剑心",
          "青阳仙",
          "武剑心",
          "武剑心",
          "武剑心"
      ],
      "army": [
          "庄聚贤",
          "庄聚贤",
          "庄聚贤",
          "庄聚贤",
          "庄聚贤",
          "庄聚贤",
          "庄聚贤",
          "庄聚贤",
          "庄聚贤",
          "庄聚贤"
      ]
  },
  {
      "lv": 150,
      "name": "体魄挑战",
      "reward": "体魄符文",
      "player": [
          "魅影客",
          "魅影客",
          "魅影客"
      ],
      "army": [
          "道玄尘",
          "道玄尘",
          "道玄尘",
          "道玄尘",
          "道玄尘",
          "道玄尘",
          "道玄尘",
          "道玄尘",
          "道玄尘",
          "道玄尘"
      ]
  },
  //########################主角挑战完结
  {
      "lv": 175,
      "name": "洪水挑战",
      "reward": "洪水符文",
      "player": [
          "高太公",
          "高太公",
          "高太公",
          "高太公",
          "高太公"
      ],
      "army": [
          "奔波儿灞",
          "奔波儿灞",
          "奔波儿灞",
          "奔波儿灞",
          "奔波儿灞"
      ]
  },
  {
      "lv": 200,
      "name": "刀法挑战",
      "reward": "刀法符文",
      "map":"地形_水",
      "player": [
          "倚海龙",
          "倚海龙",
          "倚海龙",
          "倚海龙",
          "倚海龙"
      ],
      "army": [
          "狼头精",
          "狼头精",
          "狼头精",
          "狼头精",
          "狼头精"
      ]
  },
  {
      "lv": 225,
      "name": "重甲挑战",
      "reward": "重甲符文",
      "player": [
          "斑衣鳜婆",
          "斑衣鳜婆",
          "斑衣鳜婆",
          "斑衣鳜婆",
          "斑衣鳜婆"
      ],
      "army": [
          "寅将军",
          "寅将军",
          "寅将军",
          "寅将军",
          "寅将军"
      ]
  },
  {
      "lv": 250,
      "name": "锐金挑战",
      "reward": "锐金符文",
      "player": [
          "杏仙",
          "杏仙",
          "杏仙",
          "杏仙",
          "杏仙"
      ],
      "army": [
          "白衣秀士",
          "白衣秀士"
      ]
  },
  {
      "lv": 275,
      "name": "医术挑战",
      "reward": "医术符文",
      "map":"地形_医术挑战",
      "player": [
          "通臂猿猴",
          "通臂猿猴",
          "通臂猿猴",
          "赤尻马猴",
          "赤尻马猴"
      ],
      "army": [
          "广谋",
          "广谋",
          "广谋",
          "广谋",
          "广谋",
          "广智",
          "广智",
          "广智",
          "广智",
          "广智"
      ]
  },
  {
      "lv": 300,
      "name": "仙术挑战",
      "reward": "仙术符文",
      "player": [
          "毛女侍者",
          "毛女侍者",
          "毛女侍者",
          "凌虚子",
          "凌虚子"
      ],
      "army": [
          "铁背苍狼",
          "铁背苍狼",
          "铁背苍狼",
          "铁背苍狼",
          "铁背苍狼",
          "铁背苍狼",
          "铁背苍狼",
          "铁背苍狼",
          "铁背苍狼",
          "铁背苍狼"
      ]
  },
  {
      "lv": 325,
      "name": "再生挑战",
      "reward": "再生符文",
      "army": [
          "乌鸡国皇后",
          "乌鸡国皇后",
          "乌鸡国皇后",
          "乌鸡国皇后",
          "乌鸡国皇后",
          "乌鸡国皇后",
          "乌鸡国皇后",
          "乌鸡国皇后",
          "乌鸡国皇后",
          "乌鸡国皇后"
      ],
      "player": [
          "伏狸",
          "伏狸",
          "伏狸"
      ]
  },
  {
      "lv": 350,
      "name": "佛经挑战",
      "reward": "佛经符文",
      "army": [
          "鲌太尉",
          "鲌太尉"
      ],
      "player": [
          "有来有去",
          "有来有去",
          "有来有去",
          "有来有去",
          "高翠兰"
      ]
  },
  {
      "lv": 375,
      "name": "法相挑战",
      "reward": "法相符文",
      "army": [
          "虎先锋",
          "虎先锋",
          "虎先锋"
      ],
      "player": [
          "清风",
          "清风",
          "清风",
          "清风",
          "清风"
      ]
  },
  {
      "lv": 400,
      "name": "修心挑战",
      "reward": "修心符文",
      "player": [
          "小钻风",
          "小钻风",
          "小钻风",
          "万圣公主",
          "宝林寺住持"
      ],
      "army": [
          "急如火",
          "急如火",
          "急如火",
          "急如火",
          "急如火",
          "急如火",
          "急如火"
      ]
  },

  {
      "lv": 425,
      "name": "空间挑战",
      "reward": "空间符文",
      "player": [
          "青脸儿",
          "青脸儿",
          "青脸儿",
          "青脸儿",
          "青脸儿"
      ],
      "army": [
          "黄牛精",
          "黄牛精",
          "黄牛精",
          "黄牛精",
          "黄牛精"
      ]
  },
  {
      "lv": 450,
      "name": "霸气挑战",
      "reward": "霸气符文",
      "player": [
          "怡宗皇帝",
          "辟寒大王",
          "辟寒大王",
          "辟寒大王",
          "辟寒大王",
          
      ],
      "army": [
          "都市王",
          "都市王",
          "都市王",
          "都市王",
          "都市王"
      ]
  },
  {
      "lv": 475,
      "name": "兵法挑战",
      "reward": "兵法符文",
      "player": [
          "压龙大仙",
          "压龙大仙",
          "压龙大仙",
          "压龙大仙",
          "压龙大仙"
      ],
      "army": [
          "嫦娥",
          "嫦娥",
          "嫦娥",
          "嫦娥",
          "嫦娥"
      ]
  },
  {
      "lv": 500,
      "name": "辩才挑战",
      "reward": "辩才符文",
      "player": [
          "赛太岁",
          "赛太岁",
          "锦衣校卫",
          "锦衣校卫",
          "锦衣校卫"
          
      ],
      "army": [
          "独角鬼王",
          "独角鬼王",
          "独角鬼王",
          "独角鬼王",
          "独角鬼王"
      ]
  },
  {
      "lv": 525,
      "name": "经略挑战",
      "reward": "经略符文",
      "army": [
          "虎力大仙",
          "羊力大仙",
          "鹿力大仙"
      ],
      "player": [
          "魏征",
          "巨灵神",
          "巨灵神",
          "巨灵神"
      ]
  },
  {
      "lv": 550,
      "name": "布甲挑战",
      "reward": "布甲符文",
      "player": [
          "广目天王",
          "多闻天王",
          "增长天王",
          "持国天王"
      ],
      "army": [
          "平天大圣",
          "混天大圣",
          "覆海大圣",
          "移山大圣"
      ]
  },
  {
      "lv": 575,
      "name": "杖法挑战",
      "reward": "杖法符文",
      "map":"地形_杖法挑战",
      "player": [
          "敖顺",
          "敖钦",
          "敖闰",
          "敖广",
          "小白龙"
      ],
      "army": [
          "大蛛女",
          "二蛛女",
          "三蛛女",
          "四蛛女",
          "五蛛女",
          "六蛛女",
          "七蛛女"
      ]
  },
  {
      "lv": 600,
      "name": "暗器挑战",
      "reward": "暗器符文",
      "army": [
          "蓝采和",
          "铁拐李",
          "吕洞宾",
          "曹国舅"
      ],
      "player": [
          "汉钟离",
          "何仙姑",
          "韩湘子",
          "张果老"
      ]
  },
  {
      "lv": 625,
      "name": "射术挑战",
      "reward": "射术符文",
      "army": [
          "唐僧",
          "猪刚鬣",
          "沙和尚",
          "孙悟空",
      ],
      "player": [
          "莫怜怜",
          "莫爱爱",
          "莫贾氏",
          "莫真真"
      ]
  },
  {
      "lv": 650,
      "name": "武学挑战",
      "reward": "武学符文",
      "player": [
          "二郎显圣真君"
      ],
      "army": [
          "李靖",
          "天将",
          "天将",
          "天将",
          "天将",

          "哪吒",
          "天将",
          "天将",
          "天将",
          "天将"
      ]
  },
  {
      "lv": 675,
      "name": "变化挑战",
      "reward": "变化符文",
      "player": [
          "齐天大圣"
      ],
      "army": [
          "天蓬元帅",
          "天兵",
          "天兵",
          "天兵",
          "天兵",

          "卷帘大将",
          "天兵",
          "天兵",
          "天兵",
          "天兵"
      ]
  },
  {
      "lv": 700,
      "name": "妖术挑战",
      "reward": "妖术符文",
      "map":"地形_妖术挑战",
      "army": [
          "福星",
          "福星",
          "福星",

          "禄星",
          "禄星",
          "禄星",

          "寿星",
          "寿星",
          "寿星"
      ],
      "player": [
          "六耳猕猴"
      ]
  },


  {
      "lv": 725,
      "name": "皮甲挑战",
      "reward": "皮甲符文",
      "army": [
          "大王子",
          "二王子",
          "三王子",

          "玉华州士兵",
          "玉华州士兵",
          "玉华州士兵",
          "玉华州士兵",
          "玉华州士兵"
      ],
      "player": [
          "孙悟空",
          "猪刚鬣",
          "沙和尚"
      ]
  },
  {
      "lv": 750,
      "name": "厚土挑战",
      "reward": "厚土符文",
      "army": [
          "九头虫",
          "万圣龙王",
          "万圣公主",
          "奔波儿灞",
          "灞波儿奔",
          "碧波潭小妖",
          "碧波潭小妖",
          "碧波潭小妖",
          "碧波潭小妖",
          "碧波潭小妖"
      ],
      "player": [
          "小白龙",
          "虾兵",
          "虾兵",
          "虾兵",
          "虾兵",
          "龟丞相",
          "蟹将",
          "蟹将",
          "蟹将",
          "蟹将"
      ]
  },
  {
      "lv": 775,
      "name": "巨木挑战",
      "reward": "巨木符文",
      "player": [
          "李世民",
          "秦琼",
          "尉迟恭",
          "魏征",
          "唐僧"
      ],
      "army": [
          "玉华王",
          "怡宗皇帝",
          "祭赛国国王",
          "车迟国国王",
          "宝象国国王",
          "乌鸡国国王",
          "比丘国国王",
          "灭法国国王",
      ]
  },
  {
      "lv": 800,
      "name": "剑术挑战",
      "reward": "剑术符文",
      "player": [
          "唐僧",
          "猪刚鬣",
          "沙和尚",
          "孙悟空"
      ],
      "army": [
          "镇元子",
          "清风",
          "明月",
          "五庄观道童",
          "五庄观道童",
          "五庄观道童",
          "五庄观道童",
          "五庄观道童",
          "五庄观道童",
          "五庄观道童"
      ]
  },


  {
      "lv": 825,
      "name": "念力挑战",
      "reward": "念力符文",
      "player": [
          "唐僧",
          "猪刚鬣",
          "沙和尚",
          "孙悟空"
      ],
      "army": [
          "袁守诚"
      ]
  },
  {
      "lv": 850,
      "name": "狂化挑战",
      "reward": "狂化符文",
      "army": [
          "牛魔王",
          "铁扇公主",
          "红孩儿",
          "火焰山小妖",
          "火焰山小妖",
          "火焰山小妖",
          "火焰山小妖",
          "火焰山小妖",
          "火焰山小妖",
          "火焰山小妖"
      ],
      "player": [
          "唐僧",
          "猪刚鬣",
          "沙和尚",
          "孙悟空"
      ]
  },
  {
      "lv": 875,
      "name": "臂力挑战",
      "reward": "臂力符文",
      "army": [
          "金翅大鹏",
          "青狮",
          "白象",
          "狮驼岭小妖",
          "狮驼岭小妖",
          "狮驼岭小妖",
          "狮驼岭小妖",
          "狮驼岭小妖",
          "狮驼岭小妖",
          "狮驼岭小妖"
      ],
      "player": [
          "唐僧",
          "猪刚鬣",
          "沙和尚",
          "孙悟空"
      ]
  },
  {
      "lv": 900,
      "name": "神祇挑战",
      "reward": "神祇符文",
      "army": [
          "雷声普化天尊",
          "邓忠",
          "辛环",
          "张节",
          "陶荣",
          "天兵",
          "天兵",
          "天兵",
          "天兵",
          "天兵"
      ],
      "player": [
          "唐僧",
          "猪刚鬣",
          "沙和尚",
          "孙悟空"
      ]
  },
  {
      "lv": 925,
      "name": "咒术挑战",
      "reward": "咒术符文",
      "player": [
          "唐僧",
          "猪刚鬣",
          "沙和尚",
          "孙悟空"
      ],
      "army": [
          "观世音",
          "善财童子",
          "木叉",
          "金吒",
          "哪吒",
          "南海童子",
          "南海童子",
          "南海童子",
          "南海童子",
          "南海童子"
      ]
  },
  {
      "lv": 950,
      "name": "驭兽挑战",
      "reward": "驭兽符文",
      "army": [
          "二郎显圣真君"
      ],
      "player": [
          "齐天大圣"
      ]
  },
  {
      "lv": 975,
      "name": "机关挑战",
      "reward": "机关符文",
      "player": [
          "斗战胜佛",
          "旃檀功德佛",
          "净坛使者",
          "八部天龙",
          "金身罗汉"
      ],
      "army": [
          "东华帝君",
          "元始天尊",
          "北极紫微大帝",
          "真武大帝",
          "太上老君"
      ]
  },
  {
      "lv": 1000,
      "name": "能源挑战",
      "reward": "能源符文",
      "army": [
          "玉皇大帝",
          "王母娘娘"
      ],
      "player": [
          "斗战胜佛",
          "旃檀功德佛",
          "净坛使者",
          "八部天龙",
          "金身罗汉"
      ]
  },
  {
      "lv": 1000,
      "name": "魂术挑战",
      "reward": "魂术符文",
      "army": [
          "如来佛祖"
      ],
      "player": [
          "斗战胜佛",
          "旃檀功德佛",
          "净坛使者",
          "八部天龙",
          "金身罗汉"
      ]
  }
];


window._CZHELPER = {

    testMainTask:function(){
        var index = 0;
        var xwMap = {};
        var npcMap ={};
    
        var bossArr = [];
        var xwArr = [];
        var npcArr =[];
    
        for(var key in _NPC){
          var npcconf = _NPC[key];
          if(npcconf.level!="D"
                &&npcconf.level!="C")
          bossArr.push({type:key,lv:_NPC[key].level});
        }
        
        for(var key in _MAINTASK){
          var taskConf = _MAINTASK[key];
          if(!taskConf.isselect){
            index++;
            var map = taskConf.map;
            var mapconf = _NPCMAP[map];
            var lv = mapconf.lv;
            var npc = mapconf.npc;
            for(var i=0;i<npc.length;i++){
              var npctype = npc[i].npc;
              var npcconf = _NPC[npctype];
              if(
                (npcconf.level=="D"
                ||npcconf.level=="C")
                &&npcconf.race!='mo'
              ){
                if(!npcMap[npctype]){
                  npcMap[npctype]=1;
                  npcArr.push({type:npctype,lv:lv});
                }
              }
              //console.log(npcconf.xw);
              for(var xw in npcconf.npcxw){
                if(!xwMap[xw]){
                  xwMap[xw]=1;
                  xwArr.push({type:xw,lv:lv});
                }
              }
            }
          }
        }
    
        bossArr.sort((a, b) => {
          var lva = _TM.getqua(a.lv);
          var lvb = _TM.getqua(b.lv);
          return lva - lvb;
        });
    
        console.log(index);
        console.log(npcArr);
        console.log(bossArr);
        console.log(xwArr);

        var level = 25;
        var configstr = "";
        var playerTeamIndex = 0;
        var armyTeamIndex = 40;
        for(var i=0;i<xwArr.length;i++){
            var xw = xwArr[i].type;
            var xwname = _XW[xw].label;
            configstr+="{lv:"+level+",name:'"+xwname+"挑战',reward:'"+xwname+"符文',player:[";
            var playerTeam = [];
            var armyTeam = [];
            for(var j=0;j<5;j++){
                var playerIndex = playerTeamIndex+j;
                var armyIndex = armyTeamIndex+j;
                playerTeam.push(npcArr[playerIndex].type);
                armyTeam.push(bossArr[armyIndex].type);
            }
            playerTeamIndex+=1;
            armyTeamIndex+=5;
            configstr+="'"+playerTeam.join("','")+"'],army:[";
            configstr+="'"+armyTeam.join("','")+"']},\n";
            level+=25;
            if(level>1000)
                level=1000;
        }

        console.log(configstr);
      },

    getEnableMap:function(){
        var selectTaskMap = {};
        var enableMap=[];
        for(var key in _MAINTASK){
            var taskConf = _MAINTASK[key];
            var nexttask = taskConf.nexttask;
            if(nexttask.length>1){
                for(var i=0;i<nexttask.length;i++){
                    var taskConf2 = _MAINTASK[nexttask[i]];
                    selectTaskMap[taskConf2.map]=1;
                }
            }
        }

        console.log(selectTaskMap);
        for(var key in _MAPCONFIG){
            
        }
    },

    getXwOrder:function(){

    },

    initXwPlayer:function(){

        var xwmap = {};

        for(var key in _XW){
            xwmap[key]=[];
        }

        for(var key in _NPC){

            if(_NPC[key].job!='无业'){
            for(var xw in _NPC[key].npcxw){

                xwmap[xw].push(key);

            }
            }
        }

        console.log(xwmap);

        return xwmap;
    },

    //(1-3)4   (2-6)8   (3-9)12   (4-12)26  (5-15)--
    initConfig:function(){

        var xwmap = _CZHELPER.initXwPlayer();

        var msg = "";
        for(var key in xwmap){

            var xwname = _XW[key].label;
            var str = "{name:'"+xwname+"挑战',reward:'"+xwname+"符文',player:["
            var playerArr = xwmap[key];
            var playernmb=0;
            var armynmb=0;

            if(playerArr.length>20){
                 playernmb=5;
                 armynmb=15;
            }else if(playerArr.length>16){
                 playernmb=4;
                 armynmb=12;
            }else if(playerArr.length>12){
                playernmb=3;
                 armynmb=9;
            }else if(playerArr.length>8){
                playernmb=2;
                armynmb=6;
            }else{
                playernmb=1;
                armynmb=3;
            }

            for(var j=0;j<playernmb;j++){
                var randomIndex = Math.floor(Math.random()*playerArr.length);
                str+="'"+playerArr[randomIndex]+"'";
                if(j<playernmb-1){
                    str+=","
                }
                playerArr.splice(randomIndex,1);
            }

            str+="],army:[";

            for(var j=0;j<armynmb;j++){
                var randomIndex = Math.floor(Math.random()*playerArr.length);
                str+="'"+playerArr[randomIndex]+"'";
                if(j<armynmb-1){
                    str+=","
                }
                playerArr.splice(randomIndex,1);
            }

            str+="]},\n";
            msg+=str;
        }
        console.log(msg);
    }

}